package com.five.wisdomEat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.five.wisdomEat.entity.BusinessInfo;
import com.five.wisdomEat.entity.BusinessStatus;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BusinessInfoMapper extends BaseMapper<BusinessInfo> {
    //查询商家数量
    @Select("SELECT COUNT(*) FROM businessinfo bi " +
            "INNER JOIN business b ON bi.b_number=b.b_number " +
            "WHERE b.settledId=1 ")
    Integer selectBusinessCount();

    //查询全部商家信息
    @Select("SELECT bi.*,bs.bs_name,s.id AS s_id,s.s_name FROM businessinfo bi " +
            "INNER JOIN business_status bs ON bi.b_status=bs.id " +
            "INNER JOIN business b ON bi.b_number = b.b_number " +
            "INNER JOIN settled s ON b.settledId=s.id")
    List<BusinessInfo> selectBusinessList();

    //根据编号查询商家信息
    @Select("SELECT  bi.*,bs.bs_name FROM businessinfo bi " +
            "INNER JOIN business_status bs ON bi.b_status=bs.id " +
            "WHERE b_number = #{bNumber}")
    List<BusinessInfo> selectBusinessListByBNumber(String bNumber);

    //添加商家
    @Insert("INSERT INTO businessinfo " +
            "(id,b_number,b_name,b_address,b_phone,b_status) " +
            "VALUES (null,#{bNumber},#{bName},#{bAddress},#{bPhone},1)")
    Integer insertBusiness(BusinessInfo businessInfo);

    //根据商家编号更新商家信息
    @Update("UPDATE businessinfo SET b_name=#{bName},b_address=#{bAddress},b_phone=#{bPhone}" +
            " WHERE b_number = #{bNumber}")
    Integer updateBusiness(BusinessInfo businessInfo);

    //根据商家编号删除商家
    @Delete("DELETE FROM businessinfo WHERE b_number = #{bNumber}")
    Integer deleteBusinessinfo(String bNumber); //删除商家个人信息

    @Delete("DELETE FROM business WHERE b_number = #{bNumber}")
    Integer deleteBusiness(String bNumber); //删除商家登录信息

    @Delete("DELETE FROM login_table WHERE business_number = #{bNumber}")
    Integer deleteBusinessLogin(String bNumber); //删除登陆表内容

    //根据商家编号商家营业
    @Update("UPDATE businessinfo SET b_status=1 WHERE b_number = #{bNumber}")
    Integer onSaleBusiness(String bNumber);

    //根据商家编号商家歇业
    @Update("UPDATE businessinfo SET b_status=2 WHERE b_number = #{bNumber}")
    Integer offShelfBusiness(String bNumber);

    //根据商家编号商家整改
    @Update("UPDATE businessinfo SET b_status=3 WHERE b_number = #{bNumber}")
    Integer rectifyBusiness(String bNumber);

    //查询商家营业状态
    @Select("SELECT * FROM business_status")
    List<BusinessStatus> selectBusinessStatus();
}
